package edu.psu.geovista.app.dataloader.v1.gui;
/*
 * ProjectNamePane.java
 *
 * Created on April 19, 2004, 2:54 PM
 */

import edu.psu.geovista.app.dataloader.v1.DataLoaders;
import edu.psu.geovista.app.dataloader.v1.actions.ActionManager;
import edu.psu.geovista.app.dataloader.v1.actions.ShowChooseData70;

import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

/**
 *
 * For asking a project name when create a new project
 * @Original Author  jinchen
 */
public class AskProjectNamePane extends ProjectPane {
    
    /** Creates new form ProjectNamePane */
    public AskProjectNamePane(DataLoaders dataloader) {
        super(dataloader);
        initComponents();
        this.add(this.getControlPane(), BorderLayout.SOUTH );
        this.setAutoDetect();
    }
     protected void setControlPane(JPanel p){
        p.add(leftBtn);
        //p.add(midBtn);
        p.add(rightBtn);

    }
    public String getSelectedProjectName() {
        return textFd.getText().trim() ;
    }
    private void  setAutoDetect(){
          //KeyAdapter keyL=new
          MyKeyAdapter ob=new MyKeyAdapter();
          textFd.addKeyListener(ob);
    }
    private class MyKeyAdapter extends KeyAdapter{
         public void keyPressed(KeyEvent e) {

        }

        public void keyReleased(KeyEvent e) {
            String pn=getSelectedProjectName();
            ShowChooseData70 act=(ShowChooseData70) dataloader.getAction(ActionManager.Act_ShowChooseData);
            Object project = dataloader.getProjBd().getProject(pn);// todo getProjectByIDIngoreCase          getConfiguror().getProjectByIDIngoreCase(pn);
            if(project!=null){//the project name is used
                act.setEnabled(false);
                alert("The name is used by another project,please change it.");


            }
            else{
                act.setEnabled(true);
                alert("  ");
            }
        }

        public void keyTyped(KeyEvent e) {
            /*String pn=getSelectedProjectName();
            ShowChooseDataAction act=(ShowChooseDataAction) dataloader.getAction(ActionManager.Act_ShowChooseData);
            ProjectType project = dataloader.getProjBd().getConfiguror().getProjectByID(pn);
            if(project!=null){//the project name is used
                act.setEnabled(false);
                alert("The name is used by another project.");


            }
            else{
                act.setEnabled(true);
                alert("  ");
            }*/
        }
        private void alert(String text){
            statusL.setText(text);
            AskProjectNamePane.this.repaint();
            AskProjectNamePane.this.revalidate() ;
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    private void initComponents() {//GEN-BEGIN:initComponents
        java.awt.GridBagConstraints gridBagConstraints;
        JPanel mainp=new JPanel();
        mainp.setLayout(new java.awt.BorderLayout());

        statusL = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        textFd = new javax.swing.JTextField();



        mainp.setBorder(new javax.swing.border.TitledBorder(null, "Please specify a name for your project:", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, DataLoaders.FONT_PAGE_TITLE,DataLoaders.COLOR_SECTION_TITLE )); //new java.awt.Font("MS Sans Serif", 1, 12),new java.awt.Color(0, 51, 255)
        //setPreferredSize(new java.awt.Dimension(200, 21));
        statusL.setText("    ");
        mainp.add(statusL, java.awt.BorderLayout.SOUTH);

        jPanel1.setLayout(new java.awt.GridBagLayout());

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.insets = new java.awt.Insets(0, 18, 0, 17);
        gridBagConstraints.weightx = 0.5;
        jPanel1.add(textFd, gridBagConstraints);
        mainp.add(jPanel1);

        setLayout(new java.awt.BorderLayout());
        add(mainp, java.awt.BorderLayout.CENTER);

    }//GEN-END:initComponents
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel jPanel1;
    private javax.swing.JLabel statusL;
    private javax.swing.JTextField textFd;




    // End of variables declaration//GEN-END:variables
    
}
